﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using RastinArgham.CRM.Business;

namespace RastinArgham.CRM.Services
{
    public class LoggingAPI : ILoggingAPI
    {
        public void LogError(string errorPath, string exceptionMessage, string exceptionDetails, string userAgent)
        {
            try
            {
                CRMRepository repository = new CRMRepository();
                ErrorLog error = new ErrorLog();
                error.Username = "RastinArgham.Website";
                error.UserAgent = userAgent;
                error.ErrorPath = errorPath;
                error.ExceptionMessage = exceptionMessage;
                error.ExceptionDetails = exceptionDetails;
                error.CreateDate = DateTime.Now;

                repository.AddErrorLog(error);
                repository.Save();
            }
            catch
            {
                // I Guess there is nothing to do when logging itslef fails!
            }
        }
    }
}
